using System.Linq;
using Magiq.Tests.Support;
using Magiq.Tests.TestModel;
using NUnit.Framework;

namespace Magiq.Tests
{
    [TestFixture]
    public abstract class BaseMagiqProviderInsertsInheritanceTest<TSuperClass, TSubClass> : BaseMagiqProviderInsertsTest<TSuperClass>
        where TSuperClass : class, ITestSuperClass<TSuperClass>, new()
        where TSubClass : class, ITestSubClass<TSuperClass>, TSuperClass, new()
    {

        protected override ITestDomain<TSuperClass> CreateTestDomain()
        {
            return new TestInheritanceDomain<TSuperClass, TSubClass>();
        }

        [Test]
        public void ShouldInsertSubclasses()
        {
            var prevCount = Destination.Count();
            var count = TestClassInstances.Count();
            var insertCount = Destination.Insert(TestClassInstances.Select(x => new TSubClass
                                                                            {
                                                                                AnotherStringProperty = x.StringProperty,
                                                                                IntProperty = x.AnotherIntProperty,
                                                                                AnotherIntProperty = 4,
                                                                                StringProperty = "lala",
                                                                                InheritorProperty = "testing"
                                                                            }));
            insertCount.Should(Be.EqualTo(count));
            Destination.Count().Should(Be.EqualTo(prevCount + insertCount));
        }
    }
}